package com.lebang.lechuangsystem.service.sys;

import com.lebang.lechuangsystem.mapper.MyBatisBaseDao;
import com.lebang.lechuangsystem.model.PageBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 通用基类Curd--<<增删改查,分页>>--
 * @Author: hwq
 * @Date: 2019/8/22 10:43
 * @Version 1.0
 */
public   class BaseService<Model, E> {
    @Autowired
    private MyBatisBaseDao<Model, Integer, E> baseMapper;
    /**
     * 分页
     * @param e
     * @return
     */
    public PageBean<Model> pageByExample(E e) {
        return new PageBean<>(baseMapper.selectByExample(e), baseMapper.countByExample(e));
    }

    /**
     * 根据id获取详情
     *
     * @param id
     * @return
     */
    public Model selectById(Integer id) {
        return baseMapper.selectByPrimaryKey(id);
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    public int deleteById(Integer id) {
        return baseMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据id修改
     *
     * @param model
     * @return
     */
    public int updateById(Model model) {
        return baseMapper.updateByPrimaryKeySelective(model);
    }

    /**
     * 新增
     *
     * @param model
     * @return
     */
    public int insertModel(Model model) {
        return baseMapper.insertSelective(model);
    }


}
